<?php

namespace module\index\controller;

use app\Controller;
use app\model\DynamicComment as Model;

class Comment extends Controller
{
    /**
     * 列表.
     * 
     */
    public function index()
    {
        $result = Model::withSearch(['status', 'dynamic_id'], input('get.'))->paginate([
            'list_rows'=> input('get.pageSize/d', 10),
        ]);
        $items = $result->items();
        foreach($items as $k => $row){
            $items[$k]['learn_status'] = empty($row->step) || $row->step < $row->serial ? 1 : 2;
        }
        return json([
            'items' => $items,
            'total' => $result->total()
        ]);
    }
    /**
     * 详情.
     * 
     * @param int $id
     */
    public function read(int $id)
    {
        $model = Model::with('learnLog')->findOrFail($id);
        $model->learn_status = empty($model->step) || $model->step < $model->serial ? 1 : 2;
        return json($model->toArray());
    }
    /**
     * 状态.
     * 
     * @param int $id
     */
    public function tree(int $dynamic_id)
    {
        return json(Model::tree($dynamic_id));
    }
}
